from core.basehandler import BaseHandler
from core.room import Room
from items.lint import Lint
from items.tears import Tears
from items.phlegm import Phlegm
from items.poison import Poison
from core.action import Action
from core.support import set_cutscene
from core.support import get_game
from rooms.victory_room import VictoryRoom

class PrisonHall(Room):
    def __init__(self, room_id):
        Room.__init__(self, room_id)    # do basic initialization for every room
        self.guard_dead = False
        
        # add inventory items
        self.add_item(Lint())
        
        # build list of actions
        self.add_action(LickGround)
        self.add_action(Cry)
        self.add_action(BackToCell)
        self.add_action(EnterWardensOffice)
        self.add_action(ExitToPrisonYard)
        self.add_action(MakePoison)
        self.add_action(SpewPoison)


    def get_description(self):
        if self.guard_dead:
            return "The guard's body is in the corner."
        else:
            return "MacGyver moves to the hallway, where he sees a prison guard who is clearly not paying attention."
        
    
    def get_image(self):
        if self.guard_dead:
            return 'prisonhall2.jpg'
        else:
            return 'prisonhall1.jpg'


class PrisonHallHandler(BaseHandler):
    
    # return class to use to create a new instance of this room
    def get_room_class(self):
        return PrisonHall

# define actions for this room

    
class LickGround(Action):
    def __init__(self):
        Action.__init__(self, "LickGround")
        self.done = False

    def get_description(self):
        return "Lick Ground"
    
    def do_action(self,game,room,request):
        if game.get_player().can_pickup():
            set_cutscene("MacGyver licks the ground and starts coughing up phlegm.")
            game.get_player().add_item(Phlegm())
            self.done = True
        return
    
    def get_method(self):
        return "get"
    
    def is_enabled(self):
        return not self.room.guard_dead and not self.done
    

class Cry(Action):
    def __init__(self):
        Action.__init__(self, "Cry")
        self.done = False

    def get_description(self):
        return "Cry"
    
    def do_action(self,game,room,request):
        if game.get_player().can_pickup():
            set_cutscene("MacGyver conjures up an image of Murdoc and produces a tear.")
            game.get_player().add_item(Tears())
            self.done = True
        return
    
    def get_method(self):
        return "get"
    
    def is_enabled(self):
        return not self.room.guard_dead and not self.done


class MakePoison(Action):
    def __init__(self):
        Action.__init__(self, "make_poison")
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Make Poison"
    
    def do_action(self,game,room,request):
        set_cutscene("Using the lint, tears and phlegm, MacGyver concocts a deadly poison.")
        game.get_player().pop_item('lint')
        game.get_player().pop_item('phlegm')
        game.get_player().pop_item('tears')
        game.get_player().add_item(Poison())
        return
    
    def get_method(self):
        return "get"
    
    def is_enabled(self):
        game = get_game()
        player = game.get_player()
        return (player.has_item('lint') and player.has_item('phlegm') and player.has_item('tears') and not self.room.guard_dead)

class SpewPoison(Action):
    def __init__(self):
        Action.__init__(self, "spew_poison")
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Spew Poison"
    
    def do_action(self,game,room,request):
        set_cutscene("MacGyver spews poison on the guard, who falls to the ground.")
        self.room.guard_dead = True
        game.get_player().pop_item('poison')
        return
    
    def get_method(self):
        return "get"
    
    def is_enabled(self):
        return get_game().get_player().has_item('poison')
    
class BackToCell(Action):
    def __init__(self):
        Action.__init__(self, "BackToCell")

    def get_description(self):
        return "Back To Cell"
    
    def do_action(self,game,room,request):
        set_cutscene("MacGyver retreats into his cell because he fears freedom.")
        return

    def get_destination(self):
        return "prisoncell"

    def get_method(self):
        return "get"
    
    def is_enabled(self):
        return self.room.guard_dead
    
    
class ExitToPrisonYard(Action):
    def __init__(self):
        Action.__init__(self, "ExitToPrisonYard")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Exit to Prison Yard"
    
    def do_action(self,game,room,request):
        if get_game().get_player().has_item('uniform1') or get_game().get_player().has_item('uniform2'):
            set_cutscene("The door creaks as MacGyver slips outside.")
        else:
            game.get_room('victory_room',VictoryRoom).set_image('fugitive.jpg')
            game.get_room('victory_room',VictoryRoom).set_description('MacGyver entered the yard without a disguise. He is captured and returned to his cell.')
        return
    
    def get_destination(self):
        if get_game().get_player().has_item('uniform1') or get_game().get_player().has_item('uniform2'):
            return 'prisonyard'
        else:
            return 'victory_room'
    
    def get_method(self):
        return "get"
    
    def is_enabled(self):
        return self.room.guard_dead
    

class EnterWardensOffice(Action):
    def __init__(self):
        Action.__init__(self, "EnterWardensOffice")    # do basic initialization for every action
    
    # return description of action (used in label on webpage)
    def get_description(self):
        return "Enter Warden's Office"
    
    def do_action(self,game,room,request):
        set_cutscene("MacGyver slips quietly into the warden's office.")
        return
    
    def get_destination(self):
        return 'wardensoffice'
    
    def get_method(self):
        return "get"
    
    def is_enabled(self):
        return self.room.guard_dead